/*
 * main.cpp
 *
 * Created by KavenFan on 03/11/2015.
 * Copyright (c) 2013 KavenFan. All rights reserved.
*/
#include <string.h>

#include "mytimelib.h"
#include "test.h"

void test();

int main(int argc, char* argv[]) {
    test();
    return 0;
}

void test() {
    fprintf(stdout, "---- start of test -----------\n\n");
    const time_t time_20150115 = 1421254861;
    char buff[TIME_FORMAT_SIZE] = {0};

    TEST(get_hour(time_20150115) == 1);
    TEST(get_hour() == get_hour(NOW()));
    TEST(get_hour(convert_time("2015-01-15 23:59:59")) == 23);
    TEST(get_hour(convert_time("2015-01-16 00:00:01")) == 0);
    TEST(get_hour(convert_time("2015-01-15 00:00:01")) == 0);

    TEST(get_day(time_20150115) == 15);
    TEST(get_day() == get_day(NOW()));
    TEST(get_day(convert_time("2015-01-31 00:00:01")) == 31);
    TEST(get_day(convert_time("2015-01-01 00:00:01")) == 1);

    TEST(get_month() == get_month(NOW()));
    TEST(get_month(time_20150115) == 1);
    TEST(get_month(convert_time("2015-12-01 00:00:01")) == 12);

    TEST(get_weekday() == get_weekday(NOW()));
    TEST(get_weekday(get_day_start_by_diff(-1, time_20150115)) == F_WEDNESDAY);
    TEST(get_weekday(time_20150115) == F_THURSDAY);
    TEST(get_weekday(get_day_start_by_diff(1, time_20150115)) == F_FRIDAY);
    TEST(get_weekday(get_day_start_by_diff(3, time_20150115)) == F_SUNDAY);

    TEST(convert_time(NULL) == NOW());
    TEST(convert_time("2015-01-15 01:01:01") == time_20150115);
    TEST(strcmp(convert_time(time_20150115, buff), "2015-01-15 01:01:01") == 0);

    TEST(get_day_diff(time_20150115, time_20150115) == 0);

    TEST(get_hour_start() == get_hour_start(NOW()));
    TEST(get_hour_start(time_20150115)
            == convert_time("2015-01-15 01:00:00"));

    TEST(get_day_start() == get_day_start(NOW()));
    TEST(get_day_start(time_20150115)
            == convert_time("2015-01-15 00:00:00"));
    TEST(get_day_start_by_diff(1, time_20150115)
            == convert_time("2015-01-16 00:00:00"));

    TEST(get_tommorrow_start() == get_tommorrow_start(NOW()));
    TEST(get_tommorrow_start(time_20150115)
            == convert_time("2015-01-16 00:00:00"));

    TEST(get_yesterday_start() == get_yesterday_start(NOW()));
    TEST(get_yesterday_start(time_20150115)
            == convert_time("2015-01-14 00:00:00"));

    TEST(get_next_monday_start() == get_next_monday_start(NOW()));
    TEST(get_next_monday_start(time_20150115)
            == convert_time("2015-01-19 00:00:00"));

    TEST(get_month_start() == get_month_start(NOW()));
    TEST(get_month_start(time_20150115)
            == convert_time("2015-01-01 00:00:00"));
    TEST(get_next_month_start(time_20150115)
            == convert_time("2015-02-01 00:00:00"));

    TEST(is_now_valid(0, 0) == false);
    TEST(is_now_valid(NOW(), NOW()) == true);
    TEST(is_now_valid(0, NOW()+100) == true);
    TEST(is_now_valid(NOW(), convert_time("2020-01-01 00:00:00")) == true);
    TEST(is_weekday_valid(F_THURSDAY, time_20150115) == true);
    TEST(is_weekday_valid(F_SUNDAY, time_20150115) == false);
    TEST(is_day_valid(15, time_20150115) == true);
    TEST(is_day_valid(0, time_20150115) == false);
    TEST(false);
    TEST(true);


    fprintf(stdout, "\n---- end of test -----------\n\n");
}
